﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Web.Profile;

namespace WebSite.admin
{
    public partial class addtemplate : System.Web.UI.Page
    {
      

        // Methods
        public void Button1_Click(object sender, EventArgs e)
        {
            upload upload = new upload();
            string str = upload.Up(this.file1, "../uploadfile/template/");
            base.Response.Write(upload.Resup[Convert.ToInt32(str)]);
            this.picfile.Text = upload.s;
        }

        public void ImageButton1_Click1(object sender, ImageClickEventArgs e)
        {
            if (base.Request.QueryString["tid"] != null)
            {
                SQLAccess.DoSql("update DB_Model set modelname='" + re.replace(this.modelname.Text) + "',picfile='" + re.replace(this.picfile.Text) + "',width1=" + re.replace(this.width1.Text) + ",height1=" + re.replace(this.height1.Text) + ",width2=" + re.replace(this.width2.Text) + ",height2=" + re.replace(this.height2.Text) + ",width3=" + re.replace(this.width3.Text) + ",height3=" + re.replace(this.height3.Text) + ",width4=" + re.replace(this.width4.Text) + ",height4=" + re.replace(this.height4.Text) + ",width5=" + re.replace(this.width5.Text) + ",height5=" + re.replace(this.height5.Text) + ",width6=" + re.replace(this.width6.Text) + ",height6=" + re.replace(this.height6.Text) + " where modelid=" + base.Request.QueryString["tid"] + "");
                base.Response.Write("<script language='javascript'>alert('模板信息修改成功');window.location.href='template.aspx';</script>");
                base.Response.End();
            }
            else
            {
                SQLAccess.DoSql("insert into DB_Model (modelname,picfile,width1,height1,width2,height2,width3,height3,width4,height4,width5,height5,width6,height6,gnames) values ('" + re.replace(this.modelname.Text) + "','" + re.replace(this.picfile.Text) + "'," + re.replace(this.width1.Text) + "," + re.replace(this.height1.Text) + "," + re.replace(this.width2.Text) + "," + re.replace(this.height2.Text) + "," + re.replace(this.width3.Text) + "," + re.replace(this.height3.Text) + "," + re.replace(this.width4.Text) + "," + re.replace(this.height4.Text) + "," + re.replace(this.width5.Text) + "," + re.replace(this.height5.Text) + "," + re.replace(this.width6.Text) + "," + re.replace(this.height6.Text) + ",'template')");
                base.Response.Write("<script language='javascript'>alert('模板信息添加成功');window.location.href='template.aspx';</script>");
                base.Response.End();
            }
        }

        public void Page_Load(object sender, EventArgs e)
        {
            if (this.Session["Adminlogin"] == null)
            {
                base.Response.Write("<script language=javascript>window.top.location.href='login.aspx';</script>");
                base.Response.End();
            }
            if (!base.IsPostBack && (base.Request.QueryString["tid"] != null))
            {
                this.upbind();
                this.Label1.Text = "修改模板信息";
            }
        }

        private void upbind()
        {
            string sql = "select top 1 * from DB_Model where modelid=" + base.Request.QueryString["tid"];
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            this.modelname.Text = table.Rows[0]["modelname"].ToString();
            this.picfile.Text = table.Rows[0]["picfile"].ToString();
            this.width1.Text = table.Rows[0]["width1"].ToString();
            this.height1.Text = table.Rows[0]["height1"].ToString();
            this.width2.Text = table.Rows[0]["width2"].ToString();
            this.height2.Text = table.Rows[0]["height2"].ToString();
            this.width3.Text = table.Rows[0]["width3"].ToString();
            this.height3.Text = table.Rows[0]["height3"].ToString();
            this.width4.Text = table.Rows[0]["width4"].ToString();
            this.height4.Text = table.Rows[0]["height4"].ToString();
            this.width5.Text = table.Rows[0]["width5"].ToString();
            this.height5.Text = table.Rows[0]["height5"].ToString();
            this.width6.Text = table.Rows[0]["width6"].ToString();
            this.height6.Text = table.Rows[0]["height6"].ToString();
        }

        // Properties
        public global_asax ApplicationInstance
        {
            get
            {
                return (global_asax)this.Context.ApplicationInstance;
            }
        }

        public DefaultProfile Profile
        {
            get
            {
                return (DefaultProfile)this.Context.Profile;
            }
        }

    }
}